#include "Log.h"

Log::Log() {
}

Log::Log(string filename) {
	this->filename = filename;
	this->is_debug = false;
}

Log::Log(Log &l){
	filename = l.filename;
	is_debug = l.is_debug;
}

Log& Log::operator=(const Log &l) {
	filename = l.filename;
	is_debug = l.is_debug;
	return *this;
 }

string Log::getDate(){

 	const int MAXLEN = 16;
	char s[MAXLEN];

	time_t t = time(0);
	strftime(s, MAXLEN, "%Y%m%d_%H%M%S", localtime(&t));

	return s;
}

void Log::activeDebug(bool active){
	is_debug = active;
}

void Log::write(string logline){

	if (!m_stream.is_open()){
		m_stream.open(filename.c_str(),ios::app);
	}

	if (is_debug)
	{
		cout << "[" << getDate() << "]" << logline << endl;;
	}
	m_stream << "[" << getDate() << "]" << logline << endl;
}

Log::~Log(){
  m_stream.close();
}
